<template>
  <div class="control">
    <div class="column marginR-40">
      <div class="legend-title">{{ column1Title }}</div>
      <div class="legend">
        <div v-for="(item, index) in legendItems" :key="index" class="legend-item">
          <div class="legend-color" :style="{ backgroundColor: item.color }"></div>
          <div class="legend-label">{{ item.label }}</div>
        </div>
      </div>
    </div>
    <div class="column2 marginR-40">
      <div class="legend-title1">{{ column2Title }}</div>

      <el-radio-group v-model="selectedOption1" @change="handleOption1Change">
        <el-radio :label="option.value" v-for="(option, index) in options1" :key="index">{{ option.label }}</el-radio>
      </el-radio-group>
    </div>
    <div class="column2">
      <div class="legend-title1">{{ column3Title }}</div>
      <el-radio-group v-model="selectedOption2" @change="handleOption2Change">
        <el-radio :label="option.value" v-for="(option, index) in options2" :key="index">{{ option.label }}</el-radio>
      </el-radio-group>
    </div>
  </div>
</template>

<script setup>
import { ref, defineProps } from 'vue';

const {
  defaultSelectedOption1,
  defaultSelectedOption2,
  column1Title,
  column2Title,
  column3Title,
  legendItems,
  options1,
  options2,
} = defineProps([
  'defaultSelectedOption1',
  'defaultSelectedOption2',
  'column1Title',
  'column2Title',
  'column3Title',
  'legendItems',
  'options1',
  'options2',
]);
const emit = defineEmits(['optionSelected']);

const selectedOption1 = ref(defaultSelectedOption1);
const selectedOption2 = ref(defaultSelectedOption2);
const handleOption1Change = () => {
  selectedOption2.value = ''; // 重置另一个选项
  emit('optionSelected', selectedOption1.value, selectedOption2.value);
};
const handleOption2Change = () => {
  selectedOption1.value = ''; // 重置另一个选项
  emit('optionSelected', selectedOption1.value, selectedOption2.value);
};
</script>

<style scoped lang="scss">
.control {
  display: flex;
  flex-direction: row;
  background: rgba(48, 96, 255, 0.15);
  border-radius: 0px 0px 0px 0px;
  opacity: 1;
  border: 1px solid #0190f9;
  padding: 15px 11px;
}

.column {
  flex-direction: column;
  display: flex;
}
.marginR-40 {
  margin-right: 40px;
}
.column2 {
  flex: 2;
  flex-direction: column;
  display: flex;
}
.legend {
  display: flex;
  flex-direction: column;
  flex-wrap: wrap;
  margin-top: 10px;
}

.legend-item {
  margin-top: 7px;
  display: flex;
  align-items: center;
}
.legend-item:first-child {
  margin-top: 0;
}

.legend-color {
  width: 12px;
  height: 12px;
}

.legend-label {
  font-size: 12px;
  font-family: Helvetica Neue LT Pro-55 Roman, Helvetica Neue LT Pro;
  font-weight: normal;
  color: #ffffff;
  line-height: 23px;
  margin-left: 10px;
}

.el-radio-group {
  margin-top: 10px;
}
.legend-title {
  font-size: 14px;
  font-family: Source Han Sans CN-Regular, Source Han Sans CN;
  font-weight: 400;
  color: #ffffff;
  line-height: 23px;
}
.legend-title1 {
  font-size: 16px;
  font-family: Source Han Sans CN-Regular, Source Han Sans CN;
  font-weight: 400;
  color: #ffffff;
  letter-spacing: 5px;
  line-height: 23px;
}
:deep(.el-radio-group) {
  display: block;
}

:deep(.el-radio) {
  display: block;
}
:deep(.el-radio__label) {
  color: white;
}
</style>
